<%-- 
    Document   : registroMaterias
    Created on : 08-11-2012, 08:41:56 PM
    Author     : Susy
--%>
<%@include file="/include/header.jsp"%>
<%@include file="/include/headerBec.jsp"%>
<script>
    function load(){
        var form = document.getElementById("registroMateriaForm");
        if(form.ciclo.value != "" && form.annio.value != ""){
            if(isNaN(form.annio.value) || form.annio.value < 1900){
                $( "#dialog:ui-dialog" ).dialog( "destroy" );
                $( "#dialog-message2" ).dialog({minHeight: 70, height: 180, modal: true, buttons: {Ok: function() {$( this ).dialog( "close" );}}});
            } else {
                form.cmd.value="cargarMaterias";
                form.submit();
            }
        }else{
            $( "#dialog:ui-dialog" ).dialog( "destroy" );
            $( "#dialog-message" ).dialog({minHeight: 70, height: 180, modal: true, buttons: {Ok: function() {$( this ).dialog( "close" );}}});
        }
    }
    
    function addMateriaLista(){
        if(validarForm() == true) {
            var form = document.getElementById("registroMateriaForm");
            form.cmd.value="agregarMateriaLista";
            form.submit();
        }
        
    }
    function saveMaterias(){
        var form = document.getElementById("registroMateriaForm");
        form.cmd.value="guardarMaterias"
        form.submit();
    }
      
    function agregarMateria(){
        //var url = getBaseURL();
        //url = url + "RegistroMateria.jsa?cmd=addMateria";
        var url = "./RegistroMateria.jsa?cmd=addMateria";
        window.open(url, "carrWin", "HEIGHT=600, WIDTH=600, MODAL=YES, scrollBars=YES"); 
    }
    
    function find(codigo){
        var campos = codigo.split("|"); 
        //var url = getBaseURL();
        var form = document.getElementById("registroMateriaForm");
        //url = url + "RegistroMateria.jsa?cmd=EliminarMatxBec&carnet="+campos[0]+"&cod="+campos[1]+"&correl="+campos[2];
        var url = "./RegistroMateria.jsa?cmd=EliminarMatxBec&carnet="+campos[0]+"&cod="+campos[1]+"&correl="+campos[2];
        form.action = url;
        form.submit();
    }
    
    function validarForm(){
        var form = document.getElementById("registroMateriaForm");
        if(form.codMateria.value.trim() == "") {
            $( "#dialog:ui-dialog" ).dialog( "destroy" );
            $( "#dialog-message3" ).dialog({minHeight: 70, height: 180, modal: true, buttons: {Ok: function() {$( this ).dialog( "close" );}}});
            return false;
        }
        if(form.matricula.value.trim() == "") {
            $( "#dialog:ui-dialog" ).dialog( "destroy" );
            $( "#dialog-message4" ).dialog({minHeight: 70, height: 180, modal: true, buttons: {Ok: function() {$( this ).dialog( "close" );}}});
            return false;
        }
        var nota = form.nota.value;
        if(isNaN(nota)){
            $( "#dialog:ui-dialog" ).dialog( "destroy" );
            $( "#dialog-message5" ).dialog({minHeight: 70, height: 180, modal: true, buttons: {Ok: function() {$( this ).dialog( "close" );}}});
            return false;
        } else {
            if (String(nota).indexOf(".") < String(nota).length - 3) {
                $( "#dialog:ui-dialog" ).dialog( "destroy" );
                $( "#dialog-message5" ).dialog({minHeight: 70, height: 180, modal: true, buttons: {Ok: function() {$( this ).dialog( "close" );}}});
                return false;
            } else {
                if(nota < 0 || nota > 10) {
                    $( "#dialog:ui-dialog" ).dialog( "destroy" );
                    $( "#dialog-message5" ).dialog({minHeight: 70, height: 180, modal: true, buttons: {Ok: function() {$( this ).dialog( "close" );}}});
                    return false;
                } else {
                    return true;
                }
            }
        }
    }
</script>

<div class="content">
    <html:form action="/RegistroMateria" styleId="registroMateriaForm">
        <html:hidden property="cmd" value="cargarMaterias" />
        <table class="form">
            <caption class="titleSeg">Registro de Materias</caption>
            <tr class="campos">
                <td class="label">Ciclo:&nbsp;&nbsp;</td>
                <td class="control"><html:select property="ciclo" styleClass="tinput125">
                        <html:option value="">---Seleccione----</html:option>
                        <html:option value="1">  Ciclo I  </html:option>
                        <html:option value="2">  Ciclo II  </html:option>
                        <html:option value="3">  Ciclo III  </html:option>
                    </html:select></td>
                <td width="20px"></td>
                <td class="label">A&ntilde;o:&nbsp;&nbsp;</td>
                <td class="control"><html:text property="annio" styleClass="tinput50"></html:text></td>
                <td width="5px"></td>
                <td class="control"><html:button value="Cargar" property="cargar" styleClass="button" onclick="load();" ></html:button></td>
            </tr>
            <logic:present name="load">
                <tr class="campos">
                    <td class="label">Materia:&nbsp;&nbsp;</td>
                    <td class="control">
                        <div style="float: left; vertical-align: top">
                            <html:select property="codMateria" styleClass="tinput200">
                                <html:option value="">---Seleccione---</html:option>
                                <html:options collection="materiasList" property="codMateria"
                                              labelProperty="nombre" labelName="nombre" ></html:options>
                            </html:select>
                        </div>
                    </td>
                </tr>
                <tr class="control">
                    <td class="label">Matr&iacute;cula:&nbsp;&nbsp;</td>
                    <td class="control"><html:select property="matricula" styleClass="tinput50">
                            <html:option value="">-----</html:option>
                            <html:option value="1">  1&deg; </html:option>
                            <html:option value="2">  2&deg;  </html:option>
                            <html:option value="3">  3&deg; </html:option>
                            <html:option value="4">  4&deg;  </html:option>
                            <html:option value="5">  5&deg; </html:option>
                        </html:select>
                    </td>
                    <td width="20px"></td>
                    <td class="label">Nota Final:&nbsp;&nbsp;</td>
                    <td class="control"><html:text property="nota" styleClass="tinput50"/></td>
                </tr>
                <tr><td><br/></td></tr>
                <tr>&nbsp;</tr>
                <tr class="control">
                    <td class="label">Tutor&iacute;a:&nbsp;&nbsp;</td>
                    <td class="control"><html:checkbox property="tutoria"/></td>
                    <td></td>
                    <td class="label">Retirada:&nbsp;&nbsp;</td>
                    <td class="control"><html:checkbox property="retirada"/></td>
                </tr>
                <tr><td><br/></td></tr>
                <tr class="control">
                    <td><html:button property="add" value="Agregar Materia" styleClass="button" onclick="addMateriaLista();"/></td>
                </tr>
                <br/>
                <br />
            </logic:present>
        </table>
    </html:form>

    <hr />
    <br />

    <logic:present name="_MATERIA" scope="session">
        <display:table pagesize="10" name="_MATERIA" requestURI="" class="results" style="width:60%;" id="results"> 
            <display:column property="idCompleto" title="Quitar Materia?" decorator="com.uca.sisbec.decorators.RegMatDecorator" sortable="true" />
            <display:column property="nombreMateria" title="Materia" sortable="true" />
            <display:column property="ciclo" title="Ciclo" sortable="true"/>
            <display:column property="annio" title="A&ntilde;o" sortable="true"/>
            <display:column property="matricula" title="Matr&iacute;cula" sortable="true"/>
            <display:column property="notaFinal" title="Nota Final" sortable="true"/>
        </display:table>
        <script>
            var table = document.getElementById("results");
            var rows = table.getElementsByTagName("tr");
            for (var i = 1; i < rows.length; i++) {
                rows[i].onmouseover = function() {
                    this.className += ' hilite';
                }
                rows[i].onmouseout = function() {
                    this.className = this.className.replace(' hilite', '');
                }
            }
        </script>
    </logic:present>
    <logic:present name="load">
        <html:button property="add" value="Guardar" styleClass="button" onclick="saveMaterias();"/>
    </logic:present>

<!-- DIVS DE MENSAJES DE VALIDACIONES -->
    <div id="dialog-message" style="display: none" title="Advertencia">
	<p>
            <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
            Debe seleccionar el a&ntilde;o y el ciclo
	</p>
    </div>
    <div id="dialog-message2" style="display: none" title="Advertencia">
	<p>
            <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
            El a&ntilde;o debe ser un valor num&eacute;rico mayor o igual a 1900. Ej.: 1994, 2005, 2010, etc.
	</p>
    </div>
    
    <div id="dialog-message3" style="display: none" title="Advertencia">
	<p>
            <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
            Debe seleccionar una materia
	</p>
    </div>

    <div id="dialog-message4" style="display: none" title="Advertencia">
	<p>
            <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
            Debe seleccionar el n&uacute;mero de matr&iacute;cula en que se inscribe la materia
	</p>
    </div>

    <div id="dialog-message5" style="display: none" title="Advertencia">
	<p>
            <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
            La nota debe ser un n&uacute;mero de dos decimales mayor que 0.0 y menor que 10.0. Ej.: 7.55, 8.24, 4.72, etc.
	</p>
    </div>

<!-- ******************************** -->

</div>
<%@include file="/include/footerBec.jsp"%>
<%@include file="/include/footer.jsp" %>
